//
//  HMStatus.swift
//  HMWeibo
//
//  Created by wulei on 15/12/11.
//  Copyright © 2015年 wulei. All rights reserved.
//

import UIKit


/// 微博数据模型
class HMStatus: NSObject {
    
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    /// 微博创建时间
    var created_at: String?
    /// 缩略图数组: key:thumbnail_pic
    var pic_urls: [[String: String]]?
    /// 用户模型
    var user: HMUser?
    /// 被转发的原微博信息字段
    var retweeted_status: HMStatus?
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    // 在使用 KVC时,如果 value是一个字典,会直接给属性转成字典
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = HMUser(dict:dict)
                return
            }
        }
        
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = HMStatus(dict: dict)
                return
            }
        }
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        let keys = ["id","text","source","created_at","user","pic_urls","retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }
    
    
    
    
}
